package com.gexin.model.activity;

import com.gexin.common.utils.SQLUtils;
import com.gexin.model.activity.base.BaseMemberIntegralLog;
import com.jfinal.plugin.activerecord.Page;

import java.lang.reflect.Member;
import java.math.BigDecimal;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.ZoneOffset;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.UUID;

/**
 * 业务名称:  t_member_integral_log()
 */
@SuppressWarnings("serial")
public class MemberIntegralLog extends BaseMemberIntegralLog<MemberIntegralLog> {
    public static final MemberIntegralLog dao = new MemberIntegralLog();


    public void setIdIdAndUserIdAndintegralIncrement(String userId, BigDecimal integral, boolean status, String desc) {
        this.setId(UUID.randomUUID().toString());
        Long date = new Date().getTime();
        this.setCreateTime(date);
        this.setUpdateTime(date);
        this.setUserId(userId);
        this.setDesc(desc);
        this.setIntegralIncrement(integral);
        this.setIncomeOr(status);
    }

    public void setUserIdAndintegralAndIncrementIntegralAndStatusAndCommissionAndReserveAndDesc(
            String userId, int type, BigDecimal integral, BigDecimal incrementIntegral, boolean incomeOr,
            BigDecimal commission, BigDecimal reserve, String desc) {
        this.setId(UUID.randomUUID().toString());

        this.setUserId(userId);
        this.setType(type);
        this.setIntegral(integral);
        this.setIntegralIncrement(incrementIntegral);
        this.setIncomeOr(incomeOr);
//
        this.setCommission(commission);
        this.setReserve(reserve);
        this.setDesc(desc);

        Long date = new Date().getTime();
        this.setCreateTime(date);
        this.setUpdateTime(date);
    }


    /*--------------------------------------------------------------------------------------------------------------------------*/


    public List<MemberIntegralLog> getMemberIntegralLogs(String id) {
        List<MemberIntegralLog> dailyAndIdLog = MemberIntegralLog.dao.find(
                "select * from t_member_integral_log  where 1=1 and user_id=" + id +" order by create_time desc");
        return dailyAndIdLog;
    }

    public List<MemberIntegralLog> findYesterDayLog() {
        LocalDate startDate = LocalDate.now().plusDays(-1);
        // +8是北京时间
        Long minTime = LocalDateTime.of(startDate, LocalTime.MIN).toInstant(ZoneOffset.of("+8")).toEpochMilli();
        Long maxTime = LocalDateTime.of(startDate, LocalTime.MAX).toInstant(ZoneOffset.of("+8")).toEpochMilli();
        List<MemberIntegralLog> MemberIntegralLogList = MemberIntegralLog.dao.find("select * from t_member_integral_log" +
                " where create_time between " + minTime + " and " + maxTime + " and type=6");
        return MemberIntegralLogList;
    }


    public List<MemberIntegralLog> findYesterDayAndIdLog(String userId) {
        LocalDate startDate = LocalDate.now().plusDays(-1);
        // +8是北京时间
        Long minTime = LocalDateTime.of(startDate, LocalTime.MIN).toInstant(ZoneOffset.of("+8")).toEpochMilli();
        Long maxTime = LocalDateTime.of(startDate, LocalTime.MAX).toInstant(ZoneOffset.of("+8")).toEpochMilli();
        List<MemberIntegralLog> MemberIntegralLogList = MemberIntegralLog.dao.find(
                "select * from t_member_integral_log where create_time between " + minTime + " and " + maxTime
                        + " and type=5 and userId=" + userId);
        return MemberIntegralLogList;
    }

    public List<MemberIntegralLog> findDailyAndIdLog(String userId) {
        LocalDate startDate = LocalDate.now().plusDays(0);
        // +8是北京时间
        Long minTime = LocalDateTime.of(startDate, LocalTime.MIN).toInstant(ZoneOffset.of("+8")).toEpochMilli();
        Long maxTime = LocalDateTime.of(startDate, LocalTime.MAX).toInstant(ZoneOffset.of("+8")).toEpochMilli();
        List<MemberIntegralLog> MemberIntegralLogList = MemberIntegralLog.dao.find(
                "select * from t_member_integral_log where create_time between " + minTime + " and " + maxTime
                        + " and type=6 and user_id=" + userId);
        return MemberIntegralLogList;
    }

    public List<MemberIntegralLog> getmemberIntegralLogList(String id){
        List<MemberIntegralLog> memberIntegralLogList=MemberIntegralLog.dao.find("select * from t_member_integral_log where user_id="+id);
        return memberIntegralLogList;
    }

}
